<?php
require_once( 'mofachi.ContentData.php' );
class BlogData extends ContentData {
	protected static $tableName = "mofachi.blog";
	protected static $tableID = "blog_id";

	public function __construct() {
		parent::__construct();
		$this->field[ "visible" ] = null;
	}
	public function add() {
		static::$queryStr = "insert into blog values( '','',now(),now(),0,0,".$this->field[ "visible" ];
		static::$queryStr.= ",'".$this->field[ "title" ]."','".$this->field[ "content" ]."')";
		return parent::add();
	}
	public function update() {		
		static::$queryStr = "update blog set edit_time = now(), title='".$this->field[ "title" ];
		static::$queryStr.= "', content='".$this->field[ "content" ]."' where blog_id=".$this->field[ "blog_id" ];
		return parent::update();
	}	
	public function setVisible( $is ) {
		$db = DataConnection::getConnection();
		if( $db == null ) return false;
		
		$is = ( $is ) ? 1 : 0;
		$query = "update blog set visible = ".$is." where blog_id=".$this->field[ "blog_id" ];
		if( !$db->query($query) ) {
			$db->close();
			return false;
		}
		$db->close();
		return true;
	}
}
?>